package com.ruoyi.business.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.business.domain.Dormitory;
import com.ruoyi.business.domain.HisGuest;
import com.ruoyi.business.domain.bo.DormitoryBo;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.business.service.IHisGuestService;
import com.ruoyi.business.domain.HisGuest;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招待所使用记录
 *
 * @author songzhengsheng
 * @date 2023-07-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/guest")
public class HisGuestController extends BaseController {

    private final IHisGuestService iHisGuestService;

    /**
     * 查询招待所使用记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisGuest> list(HisGuest entity) {
        startPage();
        LambdaQueryWrapper<HisGuest> lqw = iHisGuestService.buildQueryWrapper(entity);
        List<HisGuest> list = iHisGuestService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出招待所使用记录列表
     */
    @Log(title = "招待所使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HisGuest entity, HttpServletResponse response) {
        LambdaQueryWrapper<HisGuest> lqw = iHisGuestService.buildQueryWrapper(entity);
        List<HisGuest> list = iHisGuestService.list(lqw);
        ExcelUtil.exportExcel(list, "招待所使用记录", HisGuest.class, response);
    }

    /**
     * 获取招待所使用记录详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<HisGuest> getInfo(@NotNull(message = "主键不能为空")
                               @PathVariable Long id) {
        return R.ok(iHisGuestService.getById(id));
    }

    /**
     * 新增招待所使用记录
     */
    @Log(title = "招待所使用记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HisGuest bo) {
        return toAjax(iHisGuestService.save(bo));
    }

    /**
     * 修改招待所使用记录
     */
    @Log(title = "招待所使用记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HisGuest bo) {
        return toAjax(iHisGuestService.updateById(bo));
    }

    /**
     * 删除招待所使用记录
     *
     * @param ids 主键串
     */
    @Log(title = "招待所使用记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHisGuestService.removeBatchByIds(Arrays.asList(ids), true));
    }

    /**
     * 查询招待所列表
     */
    @GetMapping("/guestlist")
    public TableDataInfo<HisGuest> guestlist() {
        List<HisGuest> list = iHisGuestService.getlist();
        return getDataTable(list);
    }
}
